﻿// JScript 文件
 var ArrAnswer = new Array();
 $(document).ready(function(){
  
     $("th:contains('编号')") .attr("width","20"); 
  $("th:contains('联系人')") .attr("width","100"); 
  $("th:contains('公司名称')") .attr("width","200"); 
  $("th:contains('联系电话')") .attr("width","100"); 
  $("th:contains('提交日期')") .attr("width","80"); 
  $("th:contains('查看答卷')") .attr("width","100");
  
  $('.flexme').flexigrid({
        title: '答卷列表',
        useRp: true,
        rp: 15,
        showTableToggleBtn: true,
        height:'auto',
        striped:false
  });
  $('#excel').click(function(){
        window.open ("SurveyExcel.aspx?qnid="+$("#ddlQN").val());       
  })
  
});
 
 function OpenDetail(qnid,Accountid)
 {
    $('#Form_Detail').dialog({
           autoOpen: false,
           width:600,
           height:400,    
           modal:true
    });
    $("#Form_Detail").dialog("open"); 
    GetAnswer(qnid,Accountid);
    GetDetail(qnid) ;
   
 }
 //获得答卷
 function GetAnswer(qnid,Accountid)
 {
    $.ajax({
    type:"GET",
    url:"Comsrv/Comsrv.aspx",
    dataType:"json",
    data:"oper=GetAnswer&qnid="+qnid+"&Accountid="+Accountid ,
    success:function(data){
            ArrAnswer = data;
        }
    });
 }
//获得问卷
 function GetDetail(qnid)
 {
    $.ajax({
    type:"GET",
    url:"Comsrv/Comsrv.aspx",
    dataType:"json",
    data:"oper=GetQuestionnaire&qnid="+qnid,
    success:function(data){
     ArrayForm = data[0].Questions;
     if ( ArrayForm.length>0 )
     {
         $("#Form_Detail").empty();
         var html ="";
         for (var i=0;i<ArrayForm.length;i++)
         {
             html+="<ul>"+ArrayForm[i].ORDERIDX+"."+ArrayForm[i].QUESTION1+"</ul><ul>";
             switch ( ArrayForm[i].TYPE )
             {
                 case "single":
                     html+=FormatSingle(ArrayForm[i]);
                 break;
                 
                 case "single_other":
                     html+=FormatSingleOther(ArrayForm[i]);
                 break;
                 
                 case "multicheck":
                     html+=FormatMulticheck(ArrayForm[i]);
                 break;
                 
                 case "multicheck_other":
                     html+=FormatMulticheckOther(ArrayForm[i]);
                 break;
                 
                 case "singleblank":
                     html+=FormatSingleBlank(ArrayForm[i]);
                 break;
             }
             html+="</ul>";
             
         }
         $("#Form_Detail").html(html);
     }
    }
    });
 }
 
 
 // JScript 文件
//格式化单选（无自填）
function FormatSingle(o)
{
    var res = "";
    for (var j=0;j<o.Options.length;j++)
    {
        var ck = "";
        var color = "" ;
        for(var x=0;x<ArrAnswer.length;x++)
        {
            if(ArrAnswer[x].OPTIONID == o.Options[j].Id)
            {
                ck="√";
                color = "style='color:red'";  
            }
        }
        
        res += "<li "+color+">&nbsp;&nbsp;"+ck+"&nbsp;"+
               String.fromCharCode(65+j)+"."+o.Options[j].LABEL+"</li>";
    }
    return res;                   
}

//格式化单选（有自填）
function FormatSingleOther(o)
{
    var res = "";
    var remark = "";
    for (var j=0;j<o.Options.length;j++)
    {
        var ck = "";
        var color = "" ;
        for(var x=0;x<ArrAnswer.length;x++)
        {
            if(ArrAnswer[x].OPTIONID == o.Options[j].Id)
            {
                 ck="√";
                 color = "style='color:red'";
               
            }
            
            if(ArrAnswer[x].OPTIONID==-1&&ArrAnswer[x].QUESTIONID == o.Id)
            {
                remark = ArrAnswer[x].ANSWERTEXT;
            }
        }
        
        res += "<li "+color+">&nbsp;&nbsp;"+ck+"&nbsp;"+
               String.fromCharCode(65+j)+"."+o.Options[j].LABEL+"</li>";
    }
    res += "<div><textarea ID='Option_"+o.ID+"_text' cols='50' rows='4'>"+remark+"</textarea></div>"
    return res;                   
}

//格式化多选（无自填）
function FormatMulticheck(o)
{
    var res = "";
    for (var j=0;j<o.Options.length;j++)
    {
        var ck = "";
        var color = "" ;
        for(var x=0;x<ArrAnswer.length;x++)
        {
            if(ArrAnswer[x].OPTIONID == o.Options[j].Id)
            {
                ck="√";
                color = "style='color:red'";  
            }
        }
         res += "<li "+color+">&nbsp;&nbsp;"+ck+"&nbsp;"+
               String.fromCharCode(65+j)+"."+o.Options[j].LABEL+"</li>";
    }
    return res;                   
}

//格式化多选（有自填）
function FormatMulticheckOther(o)
{
    var res = "";
    var remark = "";
    for (var j=0;j<o.Options.length;j++)
    {
        var ck = "";
        var color = "";
        for(var x=0;x<ArrAnswer.length;x++)
        {
            if(ArrAnswer[x].OPTIONID == o.Options[j].Id)
            {
                ck="√";
                color = "style='color:red'"                
            }
            
            if(ArrAnswer[x].OPTIONID==-1&&ArrAnswer[x].QUESTIONID == o.Id)
            {
                remark = ArrAnswer[x].ANSWERTEXT;
            }
            
            
        }
        res += "<li "+color+">&nbsp;&nbsp;"+ck+"&nbsp;"+
               String.fromCharCode(65+j)+"."+o.Options[j].LABEL+"</li>";
    }
    res += "<div><textarea ID='Option_"+o.Id+"_text' cols='50' rows='4'>"+remark+"</textarea></div>"
    return res;                   
}


//格式化问答
function FormatSingleBlank(o)
{
    var res = "";
    var text = ""
    for (var j=0;j<o.Options.length;j++)
    {
        for(var x=0;x<ArrAnswer.length;x++)
        {
            if(ArrAnswer[x].OPTIONID == o.Options[j].Id)
            {
                    text=ArrAnswer[x].ANSWERTEXT
            }
        }
    }
    res += "<div><textarea ID='Text_"+o.Id+"' name='text' cols='50' rows='4'>"+text+"</textarea></div>"
    return res;                   
}



